package server

import (
	"JudgeClient/global"
	"net/http"
	"net/http/pprof"
)

type PprofServer struct {
	mux *http.ServeMux
}

func PprofInit() {
	Pprof := PprofServer{http.NewServeMux()}
	Pprof.Start()
}

func (p *PprofServer) Start() {
	if global.Conf.Server.PprofEnable {
		p.mux.HandleFunc("/debug/pprof/", pprof.Index)
		p.mux.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline)
		p.mux.HandleFunc("/debug/pprof/profile", pprof.Profile)
		p.mux.HandleFunc("/debug/pprof/symbol", pprof.Symbol)
		p.mux.HandleFunc("/debug/pprof/trace", pprof.Trace)
		err := http.ListenAndServe(global.Conf.Server.PprofAddr, p.mux)
		if err != nil {
			global.Logger.Errorf("Pprof init err:%v", err)
		}
	}
}

func (p *PprofServer) Stop() {
}
